<template>
	<view class="page">

		<articleDom v-if="showType=='article'" :articleData="articleListData" :commentData="commentListData"
			:bizId="bizId" :dataType="dataType" />

		<shareVideo v-if="showType=='video'" :videoshort="videoshortData" :bizId="bizId" :dataType="dataType" />
		<drama v-if="showType=='drama'" :dramaDetail="dramaDetailData" :dramaPageList="dramaPageList" :bizId="bizId"
			:dataType="dataType" />
<!-- 		<launchApp :getSignature="getSignatureData"></launchApp> -->
	</view>

</template>

<script>
	const isWeChat = () => {
		const ua = navigator.userAgent.toLowerCase();
		return ua.includes('micromessenger');
	};
	const script = document.createElement('script');
	script.src = 'https://res2.wx.qq.com/open/js/jweixin-1.6.2.js';
	document.body.appendChild(script);
	// import wx from 'weixin-js-sdk';
	import shareVideo from './shareVideo.vue';
	import articleDom from './article.vue'
	import drama from './drama.vue';
	import API from '@/config/newApi.js'
	export default {
		components: {
			drama,
			articleDom,
			shareVideo,
		},
		data() {
			return {
				dataType: '',
				bizId: '',
				articleListData: null,
				commentListData: [],
				showType: 'video',
				dramaDetailData: null,
				dramaPageList: [],
				videoshortData: [],
				getSignatureData: null
			};
		},
		onShow() {
			
			if (isWeChat()) {
				this.initwxlaunch()
			}
			// dataType=shortVideo&bizId=251283809169965056
			this.dataType = this.$route.query.dataType;
			if (this.$route.query.bizId != undefined) {
				this.bizId = this.$route.query.bizId
			}
			if (this.dataType) {
				if (this.dataType.includes("article")) {

					this.articleDetails()
					this.showType = 'article'
				}
				if (this.dataType.includes("video") || this.dataType.includes("Video")) {
					this.videoshortList()
					this.showType = 'video'
				}
				if (this.dataType.includes("drama")) {
					this.dramaDetail()
					this.showType = 'drama'
				}


			}
		},
		onShareAppMessage() {

		},
		onLoad(e) {
			// this.articleDetails()
		},
		onPullDownRefresh() {

		},
		methods: {
			
			initwxlaunch() {
				let data = {
					urlToSign: window.location.href
				}
				let then=this
				this.extinfo = window.location.href.split('?')[1]
				console.log(this.extinfo)
				API.getSignature(data).then(res => {
						this.launchAppShow = true
						if (res.code === 0) {
							console.log(res, '???????????????????s')
			
							try {
								wx.config({
									debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
									appId: 'wxdcaaa0ea0430cfb1', // 必填，公众号的唯一标识
									timestamp: res.data.timeStamp, // 必填，生成签名的时间戳
									nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
									signature: res.data.signature, // 必填，签名,// 必填，签名
									// "appId": "wx1b53cb74b985fe3a",
									// "nonceStr": "hGav6f84",
									// "timeStamp": 1744796560,
									// "signature": "80bfad84f16074fbdf5f0abefe6aae0f5f047d68",
									jsApiList: ["openLocation",'onMenuShareTimeline','onMenuShareAppMessage'],
									openTagList: ['wx-open-launch-app'] // 可选，需要使用的开放标签列表
								});
			
								wx.ready(function(e) {
									console.log('微信环境初始化微信SDK成功',)
								})
								wx.error((e) => {
									console.log('初始化微信SDK失败', e)
									reject(false)
								})
							} catch (error) {
								console.log(err, '不可用')
							}
			
						}
					})
					.catch(err => {
						console.log(err)
					})
			},

			dramaPage: function() {
				API.dramaPage().then(res => {
						if (res.code === 0) {
							this.dramaPageList = res.data.records
							this.showType = 'drama'
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			dramaDetail: function() {

				let data = {
					epNoIds: [this.bizId == '' ? '227087795009093632' : this.bizId],
				}
				API.dramaDetail(data).then(res => {
						if (res.code === 0) {
							this.dramaDetailData = res.data
							this.dramaPage()

						}
					})
					.catch(err => {
						console.log(err)
					})
			},

			videoshortList: function() { //视频
				let data = {
					ids: [this.bizId == '' ? '227087795009093632' : this.bizId],
					current: 1,
					size: 5
				}
				API.videoShortList(data).then(res => {
						if (res.code === 0) {
							this.showType = 'video'
							this.videoshortData = res.data
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			articleDetails: function() { //文章
				let data = {
					id: this.bizId == '' ? '260803501235765249' : this.bizId
				}
				API.articleDetails(data).then(res => {
						if (res.code === 0) {
							if (res.data.pageJump == 100 && res.data.pageType == 101) { //条件判断满足打开外链
								window.location.href = res.data.pageValue
							} else {
								this.articleListData = res.data
								this.commentList()
							}

						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			commentList: function() {
				let data = {
					id: this.bizId == '' ? '247782707710787585' : this.bizId
				}
				API.commentList(data).then(res => {
						if (res.code === 0) {
							console.log(res.data)
							this.commentListData = res.data
							this.showType = 'article'
						}
					})
					.catch(err => {
						console.log(err)
					})
			}

		}
	};
</script>

<style scoped lang="scss">
	.page {
		overflow: auto;
	}
</style>